package com.example.jiemian2;

import java.util.ArrayList;

import com.example.jiemian.R;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;

public class SearchviewActivity extends Activity implements OnQueryTextListener {
	ListView listView;
	SearchView searchView;
	Object[] names;
	ArrayAdapter<String> adapter;
	ArrayList<String> mAllList = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.serchview_activity);
		names = loadData();
		listView = (ListView) findViewById(R.id.list);
		searchView = (SearchView) findViewById(R.id.search_view);
		listView.setAdapter(new ArrayAdapter<Object>(getApplicationContext(),
				android.R.layout.simple_expandable_list_item_1, names));
		listView.setTextFilterEnabled(true);

		searchView.setOnQueryTextListener(this);
	}

	public Object[] loadData() {
		mAllList.add("aa");
		mAllList.add("ddfa");
		mAllList.add("qw");
		mAllList.add("sd");
		mAllList.add("fd");
		mAllList.add("cf");
		mAllList.add("re");
		return mAllList.toArray();
	}

	@Override
	public boolean onQueryTextSubmit(String query) {

		return false;
	}

	@Override
	public boolean onQueryTextChange(String newText) {
		if (newText.length() != 0) {
			listView.setFilterText(newText);
		} else {
			listView.clearTextFilter();
		}
		return false;
	}
}
